import { Base } from "./base";

export class Config extends Base {
  /**
   *
   * @param name
   * @param pageNum
   * @param pageSize
   * @returns {Promise<void>}
   */
  // eslint-disable-next-line camelcase
  async list({ name, pageNum = 1, pageSize = 10 }) {
    const { data = {} } = await this.$http("post", "/api/config", {
      name,
      pageNum,
      pageSize
    });
    return data;
  }

  /**
   *
   * @param id
   * @returns {Promise<boolean>}
   */
  async del(id) {
    const { errno } = await this.$http("post", "/api/config/del", { id });
    return errno === 0;
  }

  /**
   *
   * @param name
   * @param key
   * @param value
   * @param type
   * @returns {Promise<void>}
   */
  async add({ name, key, value, type }) {
    const { errno } = await this.$http("post", "/api/config/add", {
      name,
      key,
      value,
      type
    });
    return errno === 0;
  }

  /**
   *
   * @param id
   * @param name
   * @param key
   * @param value
   * @param type
   * @returns {Promise<void>}
   */
  // eslint-disable-next-line camelcase
  async update({ id, name, key, value, type }) {
    const { errno } = await this.$http("post", "/api/config/update", {
      id,
      name,
      key,
      value,
      type
    });
    return errno === 0;
  }

  async detail({ id, key }) {
    const { data = {} } = await this.$http("post", "/api/config/detail", {
      id,
      key
    });
    return data;
  }
}
